package com.simen.hellobytes.socket;

import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

/**
 * author: SimenHi
 * create time: 2020-12-14 11:13
 * description:
 */
public class NetworkInterfaceUtil {

    public static List<NetworkInterface> getLoopbackInterface() throws SocketException {
        List<NetworkInterface> loopbackInterfaceList=new ArrayList<NetworkInterface>();

        Enumeration e = NetworkInterface.getNetworkInterfaces();
        while (e.hasMoreElements()) {
            NetworkInterface networkInterface = (NetworkInterface) e.nextElement();

            if (networkInterface.isLoopback()) {
                loopbackInterfaceList.add(networkInterface);
                //return networkInterface;
            }
        }

        return loopbackInterfaceList;
    }

}
